package trunk.component;

import trunk.res.R;

import javax.swing.*;
import java.awt.*;

/**
 * class register
 * Created by IntelliJ IDEA.
 * User: yipeipei
 * Date: 11/28/11
 * Time: 10:55 PM
 * To change this template use File | Settings | File Templates.
 */
public class Register extends JComponent implements StatusAlterable {
    private int X_OFFSET = 4;
    private int Y_OFFSET = 15;
    private int xStart;
    private int yStart;
    private int width;
    private int height;
    private String name;
    private Status status = Status.ACTIVE;

    public Register(int xStart, int yStart, int width, int height, String name) {
        this.xStart = xStart;
        this.yStart = yStart;
        this.width = width;
        this.height = height;
        this.name = name;

        this.status = Status.NORMAL;
    }

    public Register(int xStart, int yStart, int width, int height, int xoff, int yoff, String name) {
        this.xStart = xStart;
        this.yStart = yStart;
        this.width = width;
        this.height = height;
        this.X_OFFSET = xoff;
        this.Y_OFFSET = yoff;
        this.name = name;

        this.status = Status.NORMAL;
    }

    public Register(int xStart, int yStart, String name) {
        this(xStart, yStart, R.attribute.REGISTER_WIDTH, R.attribute.REGISTER_HEIGHT, name);

    }

    @Override
    public void paint(Graphics g) {
        //set color
        if (this.status == Status.NORMAL) {
            g.setColor(Color.black);
        } else if (this.status == Status.ACTIVE) {
            g.setColor(Color.red);
        }
        //paint
        g.fillRect(xStart, yStart, width, height);
        g.setColor(Color.white);
        g.drawString(this.name, xStart + X_OFFSET, yStart + Y_OFFSET);
        //restore color
        g.setColor(Color.black);
    }

    public int getxStart() {
        return xStart;
    }

    public int getyStart() {
        return yStart;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public void setStatus(Status status) {
        this.status = status;
    }
}
